

package com.hazelcast.journal;

import java.io.Serializable;
import java.util.function.Function;

/**
 * Event journal event projection expecting an integer event value and
 * projecting an increment by a specified delta.
 *
 * @param <EJ_TYPE> the type of the data-structure-specific event type
 */
class NewValueIncrementingFunction<EJ_TYPE> implements Function<EJ_TYPE, Integer>, Serializable {
    private final int delta;
    private final EventJournalEventAdapter<String, Integer, EJ_TYPE> journalEventAdapter;

    NewValueIncrementingFunction(int delta, EventJournalEventAdapter<String, Integer, EJ_TYPE> journalEventAdapter) {
        this.delta = delta;
        this.journalEventAdapter = journalEventAdapter;
    }

    @Override
    public Integer apply(EJ_TYPE input) {
        return journalEventAdapter.getNewValue(input) + delta;
    }
}
